//
//  GroupDetailInfoCell.m
//  SportSocial
//
//  Created by yull on 15/1/28.
//  Copyright (c) 2015年 yull. All rights reserved.
//

#import "GroupDetailInfoCell.h"

@implementation GroupDetailInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        CGRect rect = CGRectMake(10, 10, self.contentView.width - 20, 20);
        UILabel *labelTitle= [[UILabel alloc] initWithFrame:rect];
        labelTitle.backgroundColor = [UIColor clearColor];
        labelTitle.font = [UIFont systemFontOfSize:16.0f];
        labelTitle.textColor = [UIColor blackColor];
        labelTitle.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        labelTitle.text = @"群信息";
        [self.contentView addSubview:labelTitle];
        
        rect.origin.y = labelTitle.bottom + 10;
        self.nameLabel = [[UILabel alloc] initWithFrame:rect];
        self.nameLabel.backgroundColor = [UIColor clearColor];
        self.nameLabel.font = [UIFont systemFontOfSize:14.0f];
        self.nameLabel.textColor = RGB(135, 135, 135);
        self.nameLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        [self.contentView addSubview:self.nameLabel];
        
        rect.origin.y = self.nameLabel.bottom + 5;
        self.creatorLabel = [[UILabel alloc] initWithFrame:rect];
        self.creatorLabel.backgroundColor = [UIColor clearColor];
        self.creatorLabel.font = [UIFont systemFontOfSize:14.0f];
        self.creatorLabel.textColor = RGB(135, 135, 135);
        self.creatorLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        [self.contentView addSubview:self.creatorLabel];
        
        rect.origin.y = self.creatorLabel.bottom + 5;
        UILabel *signTitleLabel = [[UILabel alloc] initWithFrame:rect];
        signTitleLabel.backgroundColor = [UIColor clearColor];
        signTitleLabel.font = [UIFont systemFontOfSize:14.0f];
        signTitleLabel.textColor = RGB(135, 135, 135);
        signTitleLabel.text = @"群签名: ";
        signTitleLabel.width = [signTitleLabel sizeThatFits:CGSizeZero].width;
        [self.contentView addSubview:signTitleLabel];
        
        rect = CGRectMake(signTitleLabel.right, signTitleLabel.top, self.contentView.width - 10 - signTitleLabel.right, 0);
        self.annoLabel = [[UILabel alloc] initWithFrame:rect];
        self.annoLabel.backgroundColor = [UIColor clearColor];
        self.annoLabel.font = [UIFont systemFontOfSize:14.0f];
        self.annoLabel.textColor = RGB(135, 135, 135);
        self.annoLabel.numberOfLines = 0;
        self.annoLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        [self.contentView addSubview:self.annoLabel];
    }
    return self;
}

+ (CGFloat)calculateCellHeightWithText:(NSString *)anno
{
    CGSize size = [anno getSizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedSize:CGSizeMake(SCREEN_WIDTH-50, CGFLOAT_MAX)];
    return 115.0f + size.height;
}

- (void)drawCellWithName:(NSString *)name creator:(NSString *)creator anno:(NSString *)anno
{
    self.nameLabel.text = [[NSString alloc] initWithFormat:@"名称: %@",name.length ? name : @""];
    
    self.creatorLabel.text = [[NSString alloc] initWithFormat:@"创建者: %@",creator.length ? creator : @""];
    
    self.annoLabel.text = anno;
    
    CGSize size = [anno getSizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedSize:CGSizeMake(self.annoLabel.width, CGFLOAT_MAX)];
    self.annoLabel.height = size.height;
}
@end
